#include <stdio.h>
#include <stdlib.h>

#define MAXSTRS 5

int main(void)
{
    int cntr;
    FILE *pipe_fp;
    char *strings[MAXSTRS] = { "roy", "zixia", "gouki", "supper", "mmwan"};

    if((pipe_fp = popen("sort", "w")) == NULL) { // 使用popen建立管道
        perror("popen");
        exit(1);
    }

    for(cntr = 0; cntr<MAXSTRS; cntr++) {
        fputs(strings[cntr], pipe_fp);
        fputc('\n', pipe_fp);
    }

    pclose(pipe_fp); // 关闭管道
    return 0;
}